﻿
@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_LayoutForEUI.cshtml";
    var listColumns = ViewBag.Columns as List<SGArchiveSystem7x.Models.CColumnsModel>;
}

<table id="SP_Index_grid" class="easyui-datagrid" style="width:100%;" title="审批" data-options="
       rownumbers:true,
       singleSelect:true,
       autoRowHeight:false,
       pagination:true,
       fitColumns:true,
       fit:true,
       striped:true,
       checkOnSelect:false,
       selectOnCheck:false,
       toolbar:'#SP_Index_tb',
       collapsible:false,
       pageSize: @SGArchiveSystem7x.Models.CCommonsModels.PageSize,
       pageList:[10,15,20]">
    <thead frozen="true">
        <tr>
            <th data-options="field:'ck',checkbox:true"></th>
            @{foreach (var c in listColumns)
                {
                    if (c.Frozen)
                    {
                        <th field="@c.FieldValue" width="@c.Len" align="center" formatter="@c.Formate">@c.FieldText</th>
                    }

                }
            }
        </tr>
    </thead>
    <thead>
        <tr>
            @{foreach (var c in listColumns)
                {
                    if (!c.Frozen)
                    {
                        <th field="@c.FieldValue" width="@c.Len" align="center" formatter="@c.Formate">@c.FieldText</th>
                    }

                }
            }
        </tr>
    </thead>
</table>
<div id="SP_Index_tb" style="padding:2px 5px;">
    <a href="javascript:void(0);" id="SP_Index_btnAgree" class="easyui-linkbutton button-blue" iconCls="icon-redo" onclick="Agree(1)" style="width:110px;height:30px;">同意</a>
    <a href="javascript:void(0);" id="SP_Index_btnDis" class="easyui-linkbutton button-orange" iconCls="icon-redo" onclick="Agree(2)" style="width:110px;height:30px;">不同意</a>
</div>
<script>
    $(document).ready(function () {
        $('#SP_Index_grid').datagrid({
            url: '/SP/Get_ajaxSPFlowArchive?depid=' +'@ViewBag.DEPID',
            singleSelect: true,
            method: 'post',
            onLoadSuccess: function (data) {
                $('.pagination-page-list').hide();
            }
        });
        InitPagenation1();
    });
   
    function Agree(result)
    {
        var rows = $('#SP_Index_grid').datagrid('getChecked');
        if (rows.length == 0) {
            $.messager.alert('提示！', '请选择要审批的档案!', 'info');
            return false;
        }
        else
        {
            var suggest = "";
            if (result == 2) {
                $.messager.prompt('提示', '请输入审批意见', function (r) {
                    if (r) {
                        suggest = r;
                        var id = [];
                        for (var i = 0; i < rows.length; i++) {
                            id.push(rows[i].SPF_ID);
                        }
                        $.ajax({
                            url: '/SP/FlowSP',
                            type: 'post',
                            dataType: 'json',
                            data: { 'result': result, 'id': id, 'suggest': suggest },
                            success: function (data) {
                                $.messager.alert('提示', '审批成功', 'info');
                                $('#SP_Index_grid').datagrid('options').url = '/SP/Get_ajaxSPFlowArchive?depid=' + '@ViewBag.DEPID',
                                    $('#SP_Index_grid').datagrid('load');
                            }
                        });
                    }
                });
            }
            else
            {
                var id = [];
                for (var i = 0; i < rows.length; i++) {
                    id.push(rows[i].SPF_ID);
                }
                $.ajax({
                    url: '/SP/FlowSP',
                    type: 'post',
                    dataType: 'json',
                    data: { 'result': result, 'id': id, 'suggest': suggest },
                    success: function (data) {
                        $.messager.alert('提示', '审批成功', 'info');
                        $('#SP_Index_grid').datagrid('options').url = '/SP/Get_ajaxSPFlowArchive?depid=' + '@ViewBag.DEPID',
                            $('#SP_Index_grid').datagrid('load');
                    }
                });
            }
        }
    }

    function formatDate(value, row) {
        if (value != null) {
            var time = new Date(parseInt(value.substr(6, 19)))//.toLocaleDateString();//13
            return time.getFullYear() + "-" + (time.getMonth() + 1) + "-" + time.getDate() + " " + time.getHours() + ":" + time.getMinutes() + ":" + time.getSeconds();
        }
        else {
            return "";
        }
    }
    function formatStage(value, row) {
        if (value == 1) {
            return "本部门审批";
        }
        else if (value == 2) {
            return "档案归档门审批";
        }
        else { return "";}
    }
    ///初始化分页
    function InitPagenation1() {
        //设置分页控件
        var p = $('#SP_Index_grid').datagrid('getPager');
        $(p).pagination({
            onSelectPage: function (pageNumber, pageSize) {
                QueryPager1(pageNumber, pageSize);
            }
        });
    }
    ///分页查询
    function QueryPager1(num, size) {
        $('#SP_Index_grid').datagrid('options').url = '/SP/Get_ajaxSPFlowArchivePager?num=' + num + '&size=' + size;
        $('#SP_Index_grid').datagrid('reload');
        $('#SP_Index_grid').datagrid('options').pageNumber = num;
        $('#SP_Index_grid').datagrid('options').pageSize = size;
        return;
    }
</script>




